home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1999 #2
/
Amiga Plus CD - 1999 - No. 2.iso
/
System-Boost
/
Workbench
/
Archive
/
XPK
/
xpk_Source
/
examples
/
xSum.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-11-15
|
2KB
|
60 lines
/* XSum.c - sums up all bytes in a compressed or uncompressed file
*
* This is a typical read-and-process xpk application. Try it out... XSum a
* file, then compress it and XSum it again. The result should be the same.
*/
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/xpkmaster.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern struct Library *DOSBase;
struct Library *XpkBase = NULL;
char errbuf[XPKERRMSGSIZE + 1], *outbuf = NULL;
long outlen, outbuflen;
void end(char *text)
{
if(outbuf)
FreeMem (outbuf, outbuflen);
if(text)
Write (Output (), text, strlen (text));
if(XpkBase)
CloseLibrary (XpkBase);
exit (text ? 10 : 0);
}
void main(int argc, char *argv[])
{
UBYTE *ptr, *last;
ULONG sum = 0;
if(!(XpkBase = OpenLibrary (XPKNAME, 0)))
end("Cannot open " XPKNAME "\n");
if(argc != 2)
end("Usage: XSum filename\n");
if(XpkUnpackTags(
XPK_InName, argv[1], /* The file name to be read */
XPK_GetError, errbuf, /* A pointer to the error message buffer */
XPK_GetOutBuf, &outbuf, /* Sets a pointer to the output buffer */
XPK_GetOutLen, &outlen, /* Sets the number of bytes written */
XPK_GetOutBufLen, &outbuflen, /* Sets the length of the output buffer */
XPK_PassThru, TRUE, /* Will pass through uncompressed data */
TAG_DONE))
end (strcat (errbuf, "\n"));
ptr = (UBYTE *) outbuf;
last = ptr + outlen;
while (ptr < last)
sum += *ptr++;
printf ("%d\n", sum);
end (NULL);
}